<?php
namespace Home\Controller;
use Think\Controller;
class RegController extends CommonController {
    public function index(){
    	 $question = D('verify')->getOneVerify();
      
    	 $this->assign('question',$question);
// var_dump($_SESSION);
         $this->display();

    }

// public function img(){ 
// $Verify = new \Think\Verify();
// $Verify->entry();
// }
    public function checkdata(){
    	//验证密码
            $password=I('post.pass');
            $repassword=I('post.repass');
            if ($password!=$repassword) {
            	 $arr=array(
                      'error'=>1,
                      'info'=>'两次密码不一致，请重新输入！'
            	 	);
                echo  json_encode($arr);
                 exit;
            }
          //验证人工提问
           $verify= I('post.verify');
           if ($verify!=$_SESSION['answer']) {
                  $arr=array(
                      'error'=>1,
                      'info'=>'答案不对，请重新填写！'
                  	);
                  echo json_encode($arr);
                  exit;
           }

           // 验证昵称
           if (D('user')->checkNickname(I('post.nickname'))) {
           	    $arr=array(
                  'error'=>1,
                  'info'=>'昵称已存在，请重新起名'
           	    	);

           	  echo json_encode($arr);
           	  exit;
           }

            // 验证邮箱
            if (D('user')->checkEmail(I('post.email'))) {
            	$arr=array(
                  'error'=>1,
                  'info'=>'邮箱已被使用，请重新输入！'
           	    	);
            	echo json_encode($arr);
            	exit;
            }


            $data=I('post.');
            $data['password']=md5($data['pass']);
            $data['create_time']=time();
            if (M('user')->add($data)) {
            	$arr=array(
                  'error'=>0,
                  'info'=>'注册成功！'
            		);
            	echo json_encode($arr);
            	exit;
            }else{
             $arr=array(
                  'error'=>1,
                  'info'=>'注册失败！'
            		);
            	echo json_encode($arr);
            	exit;

            }

    }

 // 获取城市名字
     public function getCity($ip)
    { 

       $url= "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;

       $data = file_get_contents($url);

       $arr = json_decode($data,true);

       if($arr['code']==0){
            return $arr['data']['city'];
       }

    }

    //获取访问者的ip
    public function ip()
    {
        $ip = get_client_ip();

        var_dump($ip);
    }
}

